// ==UserScript==
// @name                AAP-Nav-Ejs
// @namespace           http://geneura.org/projects/greasemonkey
// @description         Navegación por las secciones de AAP
// @include             http://geneura.ugr.es/~jmerelo/asignaturas/*
// ==/UserScript==

GM_log('Entrando AAP-Nav-Ejs');
var clase = document.getElementsByClassName('ejercicios');
var a_nodes = new Array;
var anchors = new Array;
for ( var secs = 0; secs < clase.length; secs ++ ) {
  var thisA = clase[secs];
  GM_log('ThisA ' + secs + " " + clase[secs]);
  a_nodes[secs] = thisA;
  anchors[secs] = thisA.getAttribute('id');
  GM_log('Anchor ' + secs + " " + anchors[secs]);
}



for ( var secs = 0; secs < clase.length; secs ++ ) {
  var span = document.createElement('span');
  span.setAttribute('style','background:lightgreen');
  if ( secs > 0 ) {
    var ahref = document.createElement('a');
    ahref.setAttribute('href','#'+anchors[secs-1]);
    var txt=document.createTextNode('^');
    ahref.appendChild(txt);
    span.appendChild(ahref);
  }
  if ( secs < clase.length -1  ) {
    span.appendChild(document.createTextNode(' | '));
    var ahref = document.createElement('a');
    ahref.setAttribute('href','#'+anchors[secs+1]);
    var txt=document.createTextNode('v');
    ahref.appendChild(txt);
    span.appendChild(ahref);
  }
  a_nodes[secs].parentNode.insertBefore(span,a_nodes[secs]);
}

